<?php
if (!session_id()) session_start();
header("Expires: Mon, 26 Jul 1970 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
$C_Patch = $_SERVER['DOCUMENT_ROOT'];
include_once($C_Patch . "/app/member/include/config.inc.php");
include_once($C_Patch . "/app/member/include/address.mem.php");
include_once($C_Patch . "/app/member/include/com_chk.php");
include_once($C_Patch . "/app/member/common/function.php");
include_once($C_Patch . "/resource/lottery/result/Js_Class.php");
header("Content-type:text/html;charset=utf-8");

$val = trim($_GET['val']);
//转换大小对应字符
function dx($a)
{
    if (pk10_Dx($a) == '大') {
        return 1;
    } else {
        return 2;
    }
}

//转换单双对应字符
function ds($a)
{
    if (Ssc_Ds($a) == '单') {
        return 3;
    } else {
        return 4;
    }
}

if ($val == 1) {//号码

    $sql = "select qishu,substring(datetime,12,5) as datetime,ball_1,ball_2,ball_3,ball_4,ball_5,ball_6,ball_7,ball_8,ball_9,ball_10 from lottery_result_jssc order by id DESC limit 50";

    $query = $mysqli->query($sql);

    $res = $query->fetch_all(MYSQLI_ASSOC);

    echo json_encode($res);
    $mysqli->close();


} elseif ($val == 2) {//大小

    $sql = "select qishu,substring(datetime,12,5) as datetime,ball_1,ball_2,ball_3,ball_4,ball_5,ball_6,ball_7,ball_8,ball_9,ball_10 from lottery_result_jssc order by id DESC limit 50";

    $query = $mysqli->query($sql);

    $res = $query->fetch_all(MYSQLI_ASSOC);

    foreach ($res as $key => $value) {

        $res[$key]['ball_1'] = dx($value['ball_1']);
        $res[$key]['ball_2'] = dx($value['ball_2']);
        $res[$key]['ball_3'] = dx($value['ball_3']);
        $res[$key]['ball_4'] = dx($value['ball_4']);
        $res[$key]['ball_5'] = dx($value['ball_5']);
        $res[$key]['ball_6'] = dx($value['ball_6']);
        $res[$key]['ball_7'] = dx($value['ball_7']);
        $res[$key]['ball_8'] = dx($value['ball_8']);
        $res[$key]['ball_9'] = dx($value['ball_9']);
        $res[$key]['ball_10'] = dx($value['ball_10']);

    }
    echo json_encode($res);
    $mysqli->close();


} elseif ($val == 3) {//单双

    $sql = "select qishu,substring(datetime,12,5) as datetime,ball_1,ball_2,ball_3,ball_4,ball_5,ball_6,ball_7,ball_8,ball_9,ball_10 from lottery_result_jssc order by id DESC limit 50";

    $query = $mysqli->query($sql);

    $res = $query->fetch_all(MYSQLI_ASSOC);

    foreach ($res as $key => $value) {

        $res[$key]['ball_1'] = ds($value['ball_1']);
        $res[$key]['ball_2'] = ds($value['ball_2']);
        $res[$key]['ball_3'] = ds($value['ball_3']);
        $res[$key]['ball_4'] = ds($value['ball_4']);
        $res[$key]['ball_5'] = ds($value['ball_5']);
        $res[$key]['ball_6'] = ds($value['ball_6']);
        $res[$key]['ball_7'] = ds($value['ball_7']);
        $res[$key]['ball_8'] = ds($value['ball_8']);
        $res[$key]['ball_9'] = ds($value['ball_9']);
        $res[$key]['ball_10'] = ds($value['ball_10']);

    }
    echo json_encode($res);
    $mysqli->close();

} else if ($val == 4) {//冠亚军/龙虎

    $sql = "select qishu,substring(datetime,12,5) as datetime,ball_1,ball_2,ball_3,ball_4,ball_5,ball_6,ball_7,ball_8,ball_9,ball_10 from lottery_result_jssc order by id DESC limit 50";

    $query = $mysqli->query($sql);

    $res = $query->fetch_all(MYSQLI_ASSOC);

    $arr = array();

    foreach ($res as $key => $value) {
        $hm = array();
        $hms = array();
        $hm[] = $value['ball_1'];
        $hm[] = $value['ball_2'];
        $hm[] = $value['ball_3'];
        $hm[] = $value['ball_4'];
        $hm[] = $value['ball_5'];
        $hm[] = $value['ball_6'];
        $hm[] = $value['ball_7'];
        $hm[] = $value['ball_8'];
        $hm[] = $value['ball_9'];
        $hm[] = $value['ball_10'];

        $hms[] = $value['qishu'];
        $hms[] = $value['datetime'];
        $hms[] = Pk10_Auto_quick($hm, 1);
        $hms[] = Pk10_Auto_quick($hm, 2);
        $hms[] = Pk10_Auto_quick($hm, 3);
        $hms[] = Pk10_Auto_quick($hm, 4);
        $hms[] = Pk10_Auto_quick($hm, 5);
        $hms[] = Pk10_Auto_quick($hm, 6);
        $hms[] = Pk10_Auto_quick($hm, 7);
        $hms[] = Pk10_Auto_quick($hm, 8);
        //var_dump($hms);

        array_push($arr, $hms);

    }
    echo json_encode($arr);
    $mysqli->close();
}








